var $table = $('#table'), $button = $('#button');
var zTree, rMenu;
var infoIframe = null;
$(function() {
	getTree();
	$('#infoIframe').attr('src', RS.webPath + '/admin/user?organId=');
});
function getTree() {
	$.ajax({
			url : RS.webPath + '/admin/rsOrgan/queryTree',
			type : 'get',
			dataType : 'json',
			success : function(ret) {
				zTree = $.fn.zTree.init($("#organTree"), setting, ret);
				rMenu = $("#rMenu");
				zTree.expandAll(true);
			}
	});

}
function showRMenu(type, x, y) {
	$("#rMenu ul").show();
	if (type == "root") {
		$("#m_del").hide();
		$("#m_check").hide();
		$("#m_unCheck").hide();
	} else {
		$("#m_del").show();
		$("#m_check").show();
		$("#m_unCheck").show();
	}
	rMenu.css({
			"top" : y + "px",
			"left" : x + "px",
			"visibility" : "visible"
	});

	$("body").bind("mousedown", onBodyMouseDown);
}

function hideRMenu() {
	if (rMenu)
		rMenu.css({
			"visibility" : "hidden"
		});
	$("body").unbind("mousedown", onBodyMouseDown);
}
function onBodyMouseDown(event) {
	if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length > 0)) {
		rMenu.css({
			"visibility" : "hidden"
		});
	}
}
var zTree, rMenu;
function showInfo(id) {
	$('#infoIframe').attr('src', RS.webPath + '/admin/user?organId=' + id);
}
